/**
 * 由于配合vue-resource使用，无法使用 * 来配置，只能配置具体的值
 */
const headers = {
    'Access-Control-Allow-Origin': 'http://cms.fangxin.vdian.net:8070',
    'Access-Control-Allow-Credentials': true,
    'Access-Control-Allow-Headers': "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With",
}

let res = function (obj) {
    return function (req, res) {
        res.send({
            result: obj,
            status: {
                "status_code": "0",
                "status_reason": "success",
            },
            // _imi_body: req.body,// 从req中传入的参数；此处不回传，可以到chrome的network中查看
        })
    }
}

let category = {
    level_one_id: 25,
    level_one_name: '母婴儿童',
    level_two_id: 25,
    level_two_name: '宝宝辅食',
    level_three_id: 25,
    level_three_name: '儿童酱油',
    level_four_id: 25,
    level_four_name: '',
    related_article_num: 1,
    related_category_str: '牛奶粉（二段）;牛奶粉（三段）',
    article_num: 10,// 文章数
    status: 1, // 标识上下架状态 1上架状态 3下架状态
}

let offcategory = {
    level_one_id: 25,
    level_one_name: '母婴儿童',
    level_two_id: 25,
    level_two_name: '宝宝辅食',
    level_three_id: 25,
    level_three_name: '果泥',
    level_four_id: 25,
    level_four_name: '',
    related_article_num: 1,
    related_category_str: '牛奶粉（三段）;牛奶粉（四段）',
    article_num: 10,// 文章数
    status: 3,
}

// 例子
module.exports = function (imitator) {
// 品类页列表
    imitator({
        url: '/platform/category/search',
        headers: headers,
        result: res({
            category_num: 35, // 品类总数
            keyword: '',
            category_list: [category, category, category, offcategory, category, category, offcategory, category, category, category]
        }),
        code: 200,
        timeout: 300
    });

// 用于搜索的所有三级品类名称
    imitator({
        url: '/platform/category/all',
        headers: headers,
        result: res({
            'category_list': [{category_id: 11, category_name: '儿童奶酪'}, // value label
                {category_id: 25, category_name: 'imi纸尿裤'},
                {category_id: 1132, category_name: 'imi宝宝驱蚊液'},
                {category_id: 113, category_name: 'imi乳酸菌饮料'},
                {category_id: 79, category_name: 'imi橡皮泥'}]
        }),
        code: 200,
        timeout: 300,
    });

    // 获取关联信息的品类详情
    imitator({
        url: '/platform/category/related_detail',
        headers: headers,
        result: res({
            id: 25,
            name: '纸尿裤',
            related_category_list: [{
                category_id: 113,
                category_name: 'imi宝宝驱蚊液'
            }, {
                category_id: 79,
                category_name: 'imi橡皮泥'
            }],
        }),
        timeout: 300
    });

    // 保存关联品类
    imitator({
        url: '/platform/category/related_edit',
        headers: headers,
        result: res({
            'done': 'success'
        }),
        code: 200,
        timeout: 300
    });

    // 上架
    imitator({
        url: '/platform/category/put_on',
        headers: headers,
        result: res({
            'done': 'success'
        }),
        timeout: 300
    });

    // 下架
    imitator({
        url: '/platform/category/pull_off',
        headers: headers,
        result: res({
            'done': 'success'
        }),
        timeout: 300
    });

    // 获取品类相关图片
    imitator({
        url: '/platform/category/image_detail',
        headers: headers,
        result: res({
            category_id: 25,
            category_name: '儿童酱油',
            head_image_url: 'https://si.geilicdn.com/evaluation/safebuywebsite_1501741583165.jpg.png?w=100&h=100&zm=3',
            background_image_urls: ['https://si.geilicdn.com/evaluation/safebuywebsite_1500887934759.jpg.png?w=440&h=160',
                'https://si.geilicdn.com/evaluation/safebuywebsite_1501584276013.jpg.png?w=448&h=168'],
        }),
        timeout: 300
    });

    // 设置品类相关图片
    imitator({
        url: '/platform/category/image_edit',
        headers: headers,
        result: res({
            'done': 'success'
        }),
        timeout: 300
    });

    let article = {
        "article_id": 15,
        "title": "加湿器挑选指南",
        "head_img_url": "https://si.geilicdn.com/evaluation/safebuywebsite_1491903057781.jpg?w=200&h=200&zm=3",
        "type": 1,
        "related_category_str": "净化器;香薰机;"
    };
    let no_picture_article = {
        "article_id": 15,
        "title": "加湿器挑选指南，不带图片的文章。此文章没有相应的图片。",
        "head_img_url": "",
        "type": 1,
        "related_category_str": "净化器;香薰机;"
    };
    // 品类文章列表（所有文章）
    imitator({
        url: '/platform/article/list',
        headers: headers,
        result: res({
            article_num: 20,
            article_list: [article, no_picture_article, article, no_picture_article, article, article, article]
        }),
        timeout: 300
    });

    // 品类文章操作 置顶
    imitator({
        url: '/platform/article/stick',
        headers: headers,
        result: res({
            'done': 'success'
        }),
        timeout: 300
    });

    // 品类文章操作 上移
    imitator({
        url: '/platform/article/exchange',
        headers: headers,
        result: res({
            'done': 'success'
        }),
        timeout: 300
    });

    // 获取文章关联品类信息
    imitator({
        url: '/platform/article/related_detail',
        headers: headers,
        result: res({
            id: 15,
            name: '加湿器类型有哪些，怎么选？',
            related_category_list: [{
                "category_id": 113,
                category_name: "净化器",
            }, {
                "category_id": 79,
                "category_name": "香薰机"
            }]
        }),
        timeout: 300
    });

    // 保存文章关联品类关系
    imitator({
        url: '/platform/article/related_edit',
        headers: headers,
        result: res({
            'done': 'success'
        }),
        timeout: 300
    });

// end
}// outer

